/*
 * @Descripttion: toolkit的中的createSlice模块
 * @Author: lukasavage
 * @Date: 2021-12-07 21:45:08
 * @LastEditors: lukasavage
 * @LastEditTime: 2021-12-08 21:23:28
 */

import { createReducer, createAction } from "./";
function createSlice(options) {
	let { name, initialState = {}, reducers = {} } = options;
	let actions = {};
	const prefixReducers = {};
	Object.keys(reducers).forEach(function (key) {
		var type = getType(name, key);
		actions[key] = createAction(type);
		prefixReducers[type] = reducers[key];
	});
	let reducer = createReducer(initialState, prefixReducers);
	return {
		name,
		reducer,
		actions,
	};
}
function getType(slice, actionKey) {
	return slice + "/" + actionKey;
}
export default createSlice;
